-- hp_to_flee
-- created by shuzy
-- 生命低于%，逃跑

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,
    -- 触发
    trigger = function(who, prop, arg)
        -- 一定是要怪物
        if who.type ~= OBJECT_TYPE_MONSTER then
            return false;
        end

        local hp    = who:queryAttrib("hp");
        local endHp = math.modf(who:queryAttrib("max_hp") * prop[3] / 1000);

        if hp > endHp or hp <= 0 then
            return 0;
        end

        local grid = DungeonM.getGridByPos(who:getPos());

        -- 逃跑
        who:escape();

        -- 直接无效
        grid:changeState(GRID_STATE_DISABLE);
        grid.bonus = nil;
        EventMgr.fire(event.MONSTER_FLEE, {["pos"] = who:getPos(), });

        return true;
    end,

    clear = function(who, prop)
        -- 同步清除掉改变技能间隔的属性
        PropM.deletePropById(who, "special", "add_cd");
    end,

    record = function(target, prop, path)
        return false;
    end
};
